home *** CD-ROM | disk | FTP | other *** search
/ Disc Tracy / Disc Tracy (Wayzata Technology)(6011)(1990).bin / Modula-2 / draw3D.MOD < prev    next >
Encoding:
Text File  |  1985-07-26  |  2.5 KB  |  108 lines  |  [TEXT/MACA]

  1. MODULE Draw3D;
  2.  
  3. (*
  4.          Russell L. Schnapp -- MACINTOSH GRAPHICS IN MODULA-2
  5.                   a 1986 Prentice-Hall publication.
  6.   Distributed by permission of Prentice-Hall, Inc., Englewood Cliffs, N.J.
  7. *)
  8.  
  9. (*
  10.       Draw and rotate a three dimensional wire-frame object
  11. *)
  12.  
  13. FROM ThreeDee   IMPORT Point3D, SetRot, SetScale, 
  14.                SetTranslation, SetPerspective, 
  15.                TransformSRT, Project;
  16. FROM QuickDrawTypes IMPORT Point;
  17. FROM MiniQD         IMPORT MoveTo, LineTo, ObscureCursor;
  18. FROM Terminal       IMPORT ClearScreen, BusyRead;
  19. FROM InOut          IMPORT OpenInput, CloseInput, 
  20.                ReadInt, WriteString, Done;
  21. FROM RealInOut      IMPORT ReadReal;
  22.  
  23. CONST
  24.   maxVertices = 150;
  25.   maxEdges    = 300;
  26.  
  27. VAR
  28.   vertices:          ARRAY[1..maxVertices] OF Point3D;
  29.   projectedVertices: ARRAY[1..maxVertices] OF Point;
  30.   edges: ARRAY[1..maxEdges] OF INTEGER;
  31.   numVertices, numEdges: INTEGER;
  32.  
  33. PROCEDURE DrawEdge( from, to: INTEGER );
  34. BEGIN
  35.   WITH projectedVertices[from] DO MoveTo( 256+h, 171+v ); END;
  36.   WITH projectedVertices[to]   DO LineTo( 256+h, 171+v ); END;
  37. END DrawEdge;
  38.  
  39. PROCEDURE DisplayList;
  40. VAR
  41.   edgeIndex: INTEGER;
  42. BEGIN
  43.   FOR edgeIndex:=1 TO numEdges DO
  44.     IF edges[edgeIndex] > 0 
  45.     THEN DrawEdge( ABS(edges[edgeIndex-1]), edges[edgeIndex] );
  46.     END; (*IF*)
  47.   END; (*FOR*)
  48. END DisplayList;
  49.  
  50. PROCEDURE ProjectList; (* rotate and project all vertices *)
  51. VAR
  52.   vertIndex: INTEGER;
  53.   rotVertex: Point3D;
  54. BEGIN
  55.   FOR vertIndex:=1 TO numVertices DO
  56.     TransformSRT( vertices[vertIndex], rotVertex );
  57.     Project( rotVertex, projectedVertices[vertIndex] );
  58.   END; (*FOR*)
  59. END ProjectList;
  60.   
  61. PROCEDURE ReadList;
  62. VAR
  63.   index, edge: INTEGER;
  64. BEGIN
  65.   ClearScreen;
  66.   WriteString( "Please enter the name of a 3-D data file:" );
  67.   OpenInput( "3D" );
  68.   ReadInt( numVertices );
  69.   FOR index:=1 TO numVertices DO
  70.     WITH vertices[index] DO
  71.       ReadReal( X ); ReadReal( Y ); ReadReal( Z );
  72.     END; (*WITH*)
  73.   END; (*FOR*)
  74.   numEdges:=0;
  75.   LOOP
  76.     ReadInt( edge );
  77.     IF NOT Done THEN EXIT; END;
  78.     INC( numEdges );
  79.     edges[numEdges]:=edge;
  80.   END; (*LOOP*)
  81.   CloseInput;
  82. END ReadList;
  83.  
  84. PROCEDURE KeyWasPressed(): BOOLEAN;
  85. VAR
  86.   ch: CHAR;
  87. BEGIN
  88.   BusyRead( ch );
  89.   RETURN ch <> 0C;
  90. END KeyWasPressed;
  91.  
  92. VAR
  93.   xR, yR, zR: REAL;
  94.  
  95. BEGIN
  96.   ReadList;
  97.   SetTranslation( 0.0, 0.0, 0.0 );
  98.   SetPerspective( 220.0, -180.0 );
  99.   xR:=0.0; yR:=0.0; zR:=0.0;
  100.   ObscureCursor;
  101.   REPEAT
  102.     SetRot( xR, yR, zR );
  103.     ProjectList;
  104.     ClearScreen;
  105.     DisplayList;
  106.     xR:=xR + 8.0; yR:=yR + 10.0; zR:=zR + 12.0;
  107.   UNTIL KeyWasPressed();
  108. END Draw3D.